package com.qrcode.scan;

import net.sourceforge.zbar.Symbol;

import java.util.ArrayList;
import java.util.List;

/**
 * 一维条码、二维码各种类型简介 https://blog.csdn.net/xdg_blog/article/details/52932707
 * 在线生成各种码 https://barcode.tec-it.com/zh/
 */
public class ScanCodeFormat {
    private int mId;
    private String mName;

    public static final ScanCodeFormat NONE = new ScanCodeFormat(Symbol.NONE, "NONE");
    public static final ScanCodeFormat PARTIAL = new ScanCodeFormat(Symbol.PARTIAL, "PARTIAL");
    public static final ScanCodeFormat EAN8 = new ScanCodeFormat(Symbol.EAN8, "EAN8");
    public static final ScanCodeFormat UPCE = new ScanCodeFormat(Symbol.UPCE, "UPCE");
    public static final ScanCodeFormat ISBN10 = new ScanCodeFormat(Symbol.ISBN10, "ISBN10");
    public static final ScanCodeFormat UPCA = new ScanCodeFormat(Symbol.UPCA, "UPCA");
    public static final ScanCodeFormat EAN13 = new ScanCodeFormat(Symbol.EAN13, "EAN13");
    public static final ScanCodeFormat ISBN13 = new ScanCodeFormat(Symbol.ISBN13, "ISBN13");
    public static final ScanCodeFormat I25 = new ScanCodeFormat(Symbol.I25, "I25");
    public static final ScanCodeFormat DATABAR = new ScanCodeFormat(Symbol.DATABAR, "DATABAR");
    public static final ScanCodeFormat DATABAR_EXP = new ScanCodeFormat(Symbol.DATABAR_EXP, "DATABAR_EXP");
    public static final ScanCodeFormat CODABAR = new ScanCodeFormat(Symbol.CODABAR, "CODABAR");
    public static final ScanCodeFormat CODE39 = new ScanCodeFormat(Symbol.CODE39, "CODE39");
    public static final ScanCodeFormat PDF417 = new ScanCodeFormat(Symbol.PDF417, "PDF417");
    public static final ScanCodeFormat QRCODE = new ScanCodeFormat(Symbol.QRCODE, "QRCODE");
    public static final ScanCodeFormat CODE93 = new ScanCodeFormat(Symbol.CODE93, "CODE93");
    public static final ScanCodeFormat CODE128 = new ScanCodeFormat(Symbol.CODE128, "CODE128");

    static final List<ScanCodeFormat> ALL_FORMAT_LIST = new ArrayList<>();

    static {
        ALL_FORMAT_LIST.add(ScanCodeFormat.PARTIAL);
        ALL_FORMAT_LIST.add(ScanCodeFormat.EAN8);
        ALL_FORMAT_LIST.add(ScanCodeFormat.UPCE);
//        ALL_FORMAT_LIST.add(BarcodeFormat.ISBN10);
        ALL_FORMAT_LIST.add(ScanCodeFormat.UPCA);
        ALL_FORMAT_LIST.add(ScanCodeFormat.EAN13);
        ALL_FORMAT_LIST.add(ScanCodeFormat.ISBN13);
        ALL_FORMAT_LIST.add(ScanCodeFormat.I25);
//        ALL_FORMAT_LIST.add(BarcodeFormat.DATABAR);
        ALL_FORMAT_LIST.add(ScanCodeFormat.DATABAR_EXP);
        ALL_FORMAT_LIST.add(ScanCodeFormat.CODABAR);
        ALL_FORMAT_LIST.add(ScanCodeFormat.CODE39);
        ALL_FORMAT_LIST.add(ScanCodeFormat.PDF417);
        ALL_FORMAT_LIST.add(ScanCodeFormat.QRCODE);
        ALL_FORMAT_LIST.add(ScanCodeFormat.CODE93);
        ALL_FORMAT_LIST.add(ScanCodeFormat.CODE128);
    }

    static final List<ScanCodeFormat> ONE_DIMENSION_FORMAT_LIST = new ArrayList<>();

    static {
        ONE_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.PARTIAL);
        ONE_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.EAN8);
        ONE_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.UPCE);
//        ONE_DIMENSION_FORMAT_LIST.add(BarcodeFormat.ISBN10);
        ONE_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.UPCA);
        ONE_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.EAN13);
        ONE_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.ISBN13);
        ONE_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.I25);
//        ONE_DIMENSION_FORMAT_LIST.add(BarcodeFormat.DATABAR);
        ONE_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.DATABAR_EXP);
        ONE_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.CODABAR);
        ONE_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.CODE39);
        ONE_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.PDF417);
        ONE_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.CODE93);
        ONE_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.CODE128);
    }

    static final List<ScanCodeFormat> TWO_DIMENSION_FORMAT_LIST = new ArrayList<>();

    static {
        TWO_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.PDF417);
        TWO_DIMENSION_FORMAT_LIST.add(ScanCodeFormat.QRCODE);
    }

    static final List<ScanCodeFormat> HIGH_FREQUENCY_FORMAT_LIST = new ArrayList<>();

    static {
        HIGH_FREQUENCY_FORMAT_LIST.add(ScanCodeFormat.QRCODE);
        HIGH_FREQUENCY_FORMAT_LIST.add(ScanCodeFormat.ISBN13);
        HIGH_FREQUENCY_FORMAT_LIST.add(ScanCodeFormat.UPCA);
        HIGH_FREQUENCY_FORMAT_LIST.add(ScanCodeFormat.EAN13);
        HIGH_FREQUENCY_FORMAT_LIST.add(ScanCodeFormat.CODE128);
    }

    private ScanCodeFormat(int id, String name) {
        mId = id;
        mName = name;
    }

    public int getId() {
        return mId;
    }

    public String getName() {
        return mName;
    }

    public static ScanCodeFormat getFormatById(int id) {
        for (ScanCodeFormat format : ALL_FORMAT_LIST) {
            if (format.getId() == id) {
                return format;
            }
        }
        return ScanCodeFormat.NONE;
    }
}